﻿//格式化优先级列
var formatPriority = function (e) {
    var sData = e.value;
    var showText;
    if (sData == "1") {
        showText = "<font color='red'>特急</font>";
    } else if (sData == "2") {
        showText = "<font color='green'>紧急</font>";
    } else {
        showText = "普通";
    }
    return showText;
}

//格式化流程图列
var formatShow = function (e) {
    var row = e.record;
    var WorkFlowInstanceId =row["WorkFlowInstanceId"];
    var workflowId =row["WorkFlowId"];
    var taskCaption =row["TaskCaption"];
    var url = '"' + "../../Crm/BasePages/WorkflowMap.aspx?WorkFlowInstanceId=" + WorkFlowInstanceId + "&workflowId=" + workflowId + '"';
    var title = '"' + taskCaption + '流程图"';
    return "<a href='javascript:transForForm(" + title + "," + url + ")'>流程图</a><br />";
}
//格式化流程图列
var formatClose = function (e) {
    var row = e.record;
    var WorkFlowInstanceId = row["WorkFlowInstanceId"];
    var workflowId = row["WorkFlowId"];
    var taskCaption = row["FlowCaption"];
    var url = '"' + "../../Crm/BasePages/WorkflowMap.aspx?WorkFlowInstanceId=" + WorkFlowInstanceId + "&workflowId=" + workflowId + '"';
    var title = '"' + taskCaption + '作废"';
    if (e.value == '4') {
        return "<a  href='javascript:void(0)' onclick='ColseClick(\""+WorkFlowInstanceId+"\");'>作废流程</a>";
    }
    else {
       return "";
    }
}
//作废
function ColseClick(WorkFlowInstanceId) {
    var rows = fnGetSelectedRows();;
    var elist = [];
    dl = [];
    for (var i = 0; i < rows.length; i++) {
            elist.push(rows[i][const_entityID]);
    }
    if (confirm("是否作废此流程?")) {
        var SaveUrl = "/WorkFlow/Workformat.aspx?WorkFlowInstanceId=" + WorkFlowInstanceId + "";
        YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
            success: function (res) {
                try {
                    grid.reload();
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
    }
 }
var responseSuccess = function (res) {
    try {
        var str = res.responseText;
        if (str == "1") {
            alert("操作成功"); fnReload();
        }
        else {
            alert(str);
        }
    } catch (e) {
    }
    finally {
    }
};

var responseFailure = function (error) {
    alert("数据错误：" + error.statusText);
}
var callback = {
    success: responseSuccess,
    failure: responseFailure
};
var transForForm = function (title, url) {
    parent.addTabs(title,url);
    //parent.NeedRefreshPage = this;
}
//格式化业务名列
var formatCaption = function (e) {
    var row = e.record;
    var OperatorInstanceId = row["operatorInstanceId"];
    var WorkFlowNo = row["WorkFlowNo"];
    var WorkTaskInstanceId = row["WorkTaskInstanceId"];
    var TaskName = row["TaskCaption"];
    var IsDisplay = row["IsDisplay"];
    var sData = e.value;
    var title = '"' + sData + '"';
    var url = '"' + "../../Crm/BasePages/WorkTaskCtrlPage.aspx?title=" + sData + "&OperatorInstanceId=" + OperatorInstanceId + "&WorkTaskInstanceId=" + WorkTaskInstanceId + '"';
    var pOperatedDes =row["pOperatedDes"];
    if (TaskName.length > 1 && TaskName.substr(0, 2) == "查看") {
        url = '"' + "/Crm/BasePages/WorkTaskCtrlPage.aspx?view=check&title=" + sData + "&OperatorInstanceId=" + OperatorInstanceId + "&WorkTaskInstanceId=" + WorkTaskInstanceId + '"';
    } else {
        if (pOperatedDes.substr(pOperatedDes.length - 1, 1) == ',') {
            url = '"' + "/Crm/BasePages/WorkTaskCtrlPage.aspx?view=unDone&title=" + sData + "&OperatorInstanceId=" + OperatorInstanceId + "&WorkTaskInstanceId=" + WorkTaskInstanceId + '"';
        }
    }
   
    var sum = 0;
    var urls = "../../Images/new4.gif";
    if (IsDisplay != "") {
        var isDplay = "";
        var isnull = "  ";
        isDplay = IsDisplay.split(',');
        for (i = 0; i < isDplay.length; i++) {
            if (isDplay[i] = const_UserName) {
                sum = 1;
                break;
            }
        }
        if (sum == 0) {
            return "<a href='javascript:transForForm(" + title + "," + url + ")'>" + sData + "&nbsp;&nbsp;&nbsp;<img src= " + urls + "></a><br />";
        }
        else {
            return "<a href='javascript:transForForm(" + title + "," + url + ")'>" + sData + "</a><br />";
        }
    }
    else {
        return "<a href='javascript:transForForm(" + title + "," + url + ")'>" + sData + "&nbsp;&nbsp;&nbsp;<img  src= " + urls + "></a><br />";
    }

}
//格式化提交人
var formatSubmit = function (e) {
    var row = e.record;
    var sData = e.value;
    if (sData.length > 10) {
        var WorkFlowInstanceId =row["WorkFlowInstanceId"];
        var workflowId =row["WorkFlowId"];
        var taskCaption =row["TaskCaption"];
        var title = '"' + taskCaption + '流程图"';
        var url = '"' + "../../Crm/BasePages/WorkflowMap.aspx?WorkFlowInstanceId=" + WorkFlowInstanceId + "&workflowId=" + workflowId + '"';
        return sData.substring(0, 10) + "..." + "<a href='javascript:transForForm(" + title + "," + url + ")' style='color:red'>详细</a>";
    }
    else {
        return sData;
    }
}
var formatIsDisplay = function (e) {
    var row = e.record;
    var items = const_UserName;
    var WorkFlowInstanceId =row["WorkFlowInstanceId"];
    var WorkFlowNo =row["WorkFlowNo"];
    elCell.innerHTML = "";
    var sum = 0;
    if (sData != "") {
        var isDplay = "";
        isDplay = sData.split(',');
        for (i = 0; i < isDplay.length; i++) {
            if (isDplay[i] = const_UserName) {
                sum = 1;
                return e.value;
                break;
            }
        }
        if (sum == 0) {
            var url = "../../Images/new1.gif";
            return "<a><img src= " + url + "></a><br />";
        }
    }
    else {
        var url = "../../Images/new1.gif";
        return "<a><img src= " + url + "></a><br />";
    }
}
//自动义双击方法
function fnCustomDbClick() { }